package com.gxa.jjty.cjr.utils;

import com.gxa.jjty.core.pojo.SystemMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/12/10 11:27
 * Description:
 * Version: V1.0
 */
@Component
public class MessageUtil {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    public static final String MSG_LIST="msgList:";


    /**
     * 添加用户消息
     * @param id 用户id
     * @param systemMsg 消息对象
     */
    public void putMsg(Long id, SystemMsg systemMsg){
        redisTemplate.opsForList().leftPush(MSG_LIST+id,systemMsg);
    }

    /**
     * 根据用户id获取用户消息列表
     * @param id 用户id
     * @return 用户消息列表
     */
    public List<Object> getMsg(Long id){
        return redisTemplate.opsForList().range(MSG_LIST + id, 0, -1);
    }
}
